package com.group.dao;

import java.util.List;

import com.group.model.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

@Repository
public interface BBSDao {

	public List<Board> queryBoard(@Param("areas") String[] areas, @Param("boardId") Long boardId, @Param("start") Integer start, @Param("limit") Integer limit);

	public int queryBoardCount(@Param("areas") String[] areas, @Param("boardId") Long boardId);

	@Update("update board b set b.topicCount = (select count(*) from topic t where t.boardId = #{arg0} and t.state = 1) where b.id = #{arg0}")
	public void countTopic(Long boardId);

	@Select("select boardId from topic where id = #{arg0}")
	public Long getBoardId(Long topicId);

	public List<User> queryBoardUser(@Param("boardId") Long boardId, @Param("start") Integer start, @Param("limit") Integer limit);

	public int queryBoardUserCount(@Param("boardId") Long boardId);

	public List<Topic> queryTopic(@Param("key") String key, @Param("topicId") Long topicId, @Param("boardId") Long boardId, @Param("userId") Long userId, @Param("state") Integer state, @Param("isSelect") Integer isSelect, @Param("isAnalysis") Integer isAnalysis, @Param("start") Integer start, @Param("limit") Integer limit);

	public int queryTopicCount(@Param("key") String key, @Param("topicId") Long topicId, @Param("boardId") Long boardId, @Param("userId") Long userId, @Param("state") Integer state, @Param("isSelect") Integer isSelect, @Param("isAnalysis") Integer isAnalysis);

	public List<Topic> queryMyReplyTopic(@Param("userId") Long userId, @Param("start") Integer start, @Param("limit") Integer limit);

	public int queryMyReplyTopicCount(@Param("userId") Long userId);

	@Select("select * from board b where b.id in (select l.boardId  from boardlike l where l.userId = #{arg0})")
	public List<Board> queryMyBoard(Long userId);

	public List<TopicReply> queryTopicReply(@Param("topicId") Long topicId, @Param("topicReplyUserId") Long topicReplyUserId, @Param("state") Integer state, @Param("start") Integer start, @Param("limit") Integer limit);

	public int queryTopicReplyCount(@Param("topicId") Long topicId, @Param("topicReplyUserId") Long topicReplyUserId, @Param("state") Integer state);

	@Update("update topic t set t.replyCount = (select count(*) from topicreply r where r.topicId = #{arg0} and r.state = 1) where t.id = #{arg0}")
	public void countTopicReply(Long topicId);

	@Update("update topic t set t.state = #{arg1} where t.id = #{arg0}")
	public void updateTopicState(Long topicId, Integer state);

	@Update("update topicreply t set t.state = #{arg1} where t.id = #{arg0}")
	public void updateTopicReplyState(Long topicReplyId, Integer state);

	public List<Topic> queryBackTopic(@Param("key") String key, @Param("boardIds") List<Long> boardIds, @Param("state") Integer state, @Param("start") Integer start, @Param("limit") Integer limit);

	public int queryBackTopicCount(@Param("key") String key, @Param("boardIds") List<Long> boardIds, @Param("state") Integer state);

	public List<Board> queryBackUserBoard(@Param("key") String key, @Param("backUserId") Long backUserId, @Param("start") Integer start, @Param("limit") Integer limit);

	public int queryBackUserBoardCount(@Param("key") String key, @Param("backUserId") Long backUserId);

	@Select("select count(*) from topic t where t.userId = #{age0} and t.createTime > date_add(now(), interval - 20 second) ")
	public int countTopicFreq(Long userId);

	@Select("SELECT * FROM systempara LIMIT #{arg0},#{arg1}")
	List<SystemPara> querySystemParamList(Integer start, Integer limit);

	@Select("select count(1) from systempara")
	int queryCount();
}
